package com.mmd.redis;//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//


import com.mmd.utils.ApplicationConfigs;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class SessionCacheManager extends BaseRedisCache {
    private static final Logger log = LoggerFactory.getLogger(SessionCacheManager.class);
    private static SessionCacheManager _inst;
    private static Object _lock = new Object();
    private int exp_time = 0;

    public SessionCacheManager() {
    }

    public static SessionCacheManager inst() {
        if (_inst != null) {
            return _inst;
        } else {
            synchronized(_lock) {
                if (_inst == null) {
                    _inst = new SessionCacheManager();
                    _inst.initPool();
                }
            }

            return _inst;
        }
    }

    public void initPool() {
        if (this.pool == null) {
            try {
                String host = ApplicationConfigs.getConfig("redis.ip");
                String port = ApplicationConfigs.getConfig("redis.port");
                JedisPoolConfig poolConfig = new JedisPoolConfig();
                poolConfig.setMaxTotal(128);
                poolConfig.setMaxIdle(64);
                poolConfig.setMaxWaitMillis(1000L);
                poolConfig.setTestOnBorrow(false);
                poolConfig.setTestOnReturn(false);
                String pwd = ApplicationConfigs.getConfig("redis.pwd");
                System.out.println("redis config: host:{}, port:{}, pwd:{}" + host + "|" + port + "|" + pwd);
                log.info("redis config: host:{}, port:{}, pwd:{}", new Object[]{host, port, pwd});
                if (StringUtils.isNotEmpty(pwd)) {
                    this.pool = new JedisPool(poolConfig, host, Integer.parseInt(port), 0, pwd);
                } else {
                    this.pool = new JedisPool(poolConfig, host, Integer.parseInt(port), 0);
                }

                log.info("redis init ok, pool:{}", this.pool);
            } catch (Exception var5) {
                log.error("Couldn't create a connection, bailing out: \nIOException ", var5);
            }
        }

    }

    public void returnResource(JedisPool pool, Jedis redis) {
        if (redis != null) {
            pool.returnResource(redis);
        }

    }
}
